import 'package:favorcate/core/model/category_model.dart';
import 'package:favorcate/core/model/meal_model.dart';
import 'package:favorcate/core/viewmodel/meal_view_model.dart';
import 'package:favorcate/ui/widgets/meal_item.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:collection/collection.dart';

class ZSMealContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //获取参数
    final category =
        ModalRoute.of(context)?.settings.arguments as ZSCategoryModel;
    return Selector<ZSMealViewModel, List<ZSMealModel>>(
      selector: (ctx, mealMode) => mealMode.meals
          .where((meal) => meal.categories!.contains(category.id))
          .toList(),
      shouldRebuild: (pre, next) => !ListEquality().equals(pre, next),
      builder: (ctx, meals, child) {
        return ListView.builder(
            itemCount: meals.length,
            itemBuilder: (ctx, index) {
              return ZSMealItem(meals[index]);
            });
      },
    );
  }
}

//
// class ZSMealContent extends StatelessWidget {
//   @override
//   Widget build(BuildContext context) {
//     //获取参数
//     final category =
//         ModalRoute.of(context).settings.arguments as ZSCategoryModel;
//     return Consumer<ZSMealViewModel>(builder: (ctx, model, child) {
//       final meals = model.meals
//           .where((item) => item.categories.contains(category.id))
//           .toList();
//       return ListView.builder(
//           itemCount: meals.length,
//           itemBuilder: (ctx, index) {
//             return ListTile(title: Text(meals[index].title));
//           });
//     });
//   }
// }
